package System_code.MyBlockingQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2022-08-06
 * Time: 16:44
 */
public class Demo19 {
    public static void main(String[] args) {
        MyBlockingQueue queue=new MyBlockingQueue();
        Thread customer=new Thread(()->{
            while(true){
                try {

                    int val=queue.take();
                    System.out.println("消费元素"+val);
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        });
        customer.start();
        Thread producer=new Thread(()->{
            int n=0;
            while(true){

                try {
                    System.out.println("生产元素"+n);
                    queue.put(n);
                    n++;

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        producer.start();
    }
}
